package cn.edu.wfit.modules.learn.controller.competitionmanagement;

import java.util.List;

import cn.edu.wfit.modules.learn.domain.WfitCompetitionIndividualregistration;
import cn.edu.wfit.modules.learn.domain.dto.IndividualDetailDto;
import cn.edu.wfit.modules.learn.service.competitionmanagement.IWfitCompetitionIndividualregistrationService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;

import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 个人赛报名Controller
 * 
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/individualregistration")
public class WfitCompetitionIndividualregistrationController extends BaseController
{
    @Autowired
    private IWfitCompetitionIndividualregistrationService wfitCompetitionIndividualregistrationService;

    /**
     * 查询个人赛报名列表
     */
    @RequiresPermissions("system:individualregistration:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitCompetitionIndividualregistration wfitCompetitionIndividualregistration)
    {
        startPage();
        List<WfitCompetitionIndividualregistration> list = wfitCompetitionIndividualregistrationService.selectWfitCompetitionIndividualregistrationList(wfitCompetitionIndividualregistration);
        return getDataTable(list);
    }

    /**
     * 导出个人赛报名列表
     */
    @RequiresPermissions("system:individualregistration:export")
    @Log(title = "个人赛报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitCompetitionIndividualregistration wfitCompetitionIndividualregistration)
    {
        List<WfitCompetitionIndividualregistration> list = wfitCompetitionIndividualregistrationService.selectWfitCompetitionIndividualregistrationList(wfitCompetitionIndividualregistration);
        ExcelUtil<WfitCompetitionIndividualregistration> util = new ExcelUtil<WfitCompetitionIndividualregistration>(WfitCompetitionIndividualregistration.class);
        util.exportExcel(response, list, "个人赛报名数据");
    }

    /**
     * 获取个人赛报名详细信息
     */
    @RequiresPermissions("system:individualregistration:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wfitCompetitionIndividualregistrationService.selectWfitCompetitionIndividualregistrationById(id));
    }

    /**
     * 新增个人赛报名
     */
    @RequiresPermissions("system:individualregistration:add")
    @Log(title = "个人赛报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitCompetitionIndividualregistration wfitCompetitionIndividualregistration)
    {
        return toAjax(wfitCompetitionIndividualregistrationService.insertWfitCompetitionIndividualregistration(wfitCompetitionIndividualregistration));
    }

    /**
     * 修改个人赛报名
     */
    @RequiresPermissions("system:individualregistration:edit")
    @Log(title = "个人赛报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitCompetitionIndividualregistration wfitCompetitionIndividualregistration)
    {
        return toAjax(wfitCompetitionIndividualregistrationService.updateWfitCompetitionIndividualregistration(wfitCompetitionIndividualregistration));
    }

    /**
     * 删除个人赛报名
     */
    @RequiresPermissions("system:individualregistration:remove")
    @Log(title = "个人赛报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wfitCompetitionIndividualregistrationService.deleteWfitCompetitionIndividualregistrationByIds(ids));
    }

    /**
     * 根据学号查询个人赛记录表和竞赛信息
     *
     * @param studentId 学号
     * @return 个人赛记录表和竞赛信息
     */
    @GetMapping("/listByStudentId/{studentId}")
    public AjaxResult IndividualListByStudentId(@PathVariable("studentId") String studentId)
    {
        List<IndividualDetailDto> list = wfitCompetitionIndividualregistrationService.IndividualListByStudentId(studentId);
        return success(list);
    }
}
